package com.arong.swing.db.dao;

import java.sql.SQLException;

import com.arong.swing.db.JDBCUtils;
import com.arong.swing.db.entity.KeyCar;
import com.arong.swing.exception.AppException;
import com.arong.swing.exception.SysException;
public class KeyCarSDAO  extends BaseDAO {
	/*public KeyCarSDAO(){
		this(DB_PACKAGEDATA);
	}*/
	public KeyCarSDAO(String dbFile){
		super(dbFile);
	}
	public KeyCarSDAO(JDBCUtils jdbcUtils){
		super(jdbcUtils);
	}
	public String getCreateTableSql(){
		return "CREATE TABLE IF NOT EXISTS "+
				"KEY_CAR("+
					" CPHM  VARCHAR2(32) PRIMARY KEY,"+//车牌号码
					" CZSFZH VARCHAR2(256),"+//车主身份证号
					" CZXM VARCHAR2(256),"+//车主姓名
					" CLSBDM VARCHAR2(512),"+//车辆识别代码
					" CLYS VARCHAR2(512),"+//车辆颜色
					" FDJH VARCHAR2(512),"+//发动机号
					 " CLLB VARCHAR2(256),"+//车辆中标类别
					 " CLFS VARCHAR2(256),"+//处理方式
					 " AQMS VARCHAR2(512),"+//案情描述
					 " BKLXR VARCHAR2(512),"+//布控联系人
					 " BKLXFS VARCHAR2(512),"+//布控联系方式
					 " RWMC VARCHAR2(512),"+//任务名称
					 " RWID VARCHAR2(512),"+//任务ID
					 " PFIRSTID VARCHAR2(512),"+//布控包ID
					 " PVERID VARCHAR2(512)"+//布控包版本ID
						 ")";
		
	}
	
	/**
	 * 插入
	 * @param entity
	 * @return
	 * @throws SysException, AppException
	 */
	public  int insert(KeyCar entity) throws SysException,AppException {
		int i=0;
		try {
		 			i= jdbcUtils.insert(entity);
		} catch (SQLException e) {
			throw new SysException("add error", e);
		}
		return i;
	}

	/**
	 * 查询对象
	 * @param entity
	 * @return
	 * @throws SysException, AppException
	 */
	public  KeyCar queryBean(String cphm) throws SysException,AppException {
		KeyCar res=null;
	    try {
	    	Object[] params ={cphm,cphm,cphm};
			res=  jdbcUtils.queryBean("SELECT CPHM,CZSFZH,CZXM,CLSBDM,CLYS,FDJH,CLLB,CLFS,AQMS,BKLXR,BKLXFS,RWMC,RWID,PFIRSTID,PVERID FROM KEY_CAR WHERE CPHM=? or CLSBDM=? or FDJH=? ", KeyCar.class,params);
		} catch (SQLException e) {
			throw new SysException("queryBean对象查询 error",e);
		}
		return   res;
	}
	
}

